<button class="btn btn-primary" type="button" onclick="addScmUser()">新增</button>

<table class="table" id="userListDiv">
    <thead>
    <tr>
        <th>序号</th>
        <th>用户账号</th>
        <th>密码</th>
        <th>姓名</th>
        <th>添加日期</th>
        <th>锁定状态</th>
        <th>用户权限</th>
        <th colspan="2">操作</th>
    </tr>
    </thead>
    <tbody id="tableBody"></tbody>
</table>
<div>
    <ul id="page">分页</ul>
</div>

<script id="userListTemplate" type="text/html">
    {{each data value index}}
    {{each value.userModelList usermodel usermodels}}
    {{each usermodel.systemModelList role roleindex}}
    <tr>
        <td>{{index+1}}</td>
        <td id="account">{{value.account}}</td>
        <td>{{value.password}}</td>
        <td>{{value.name}}</td>
        <td>{{value.createDate}}</td>
        {{if value.status==1}}
        <td>锁定</td>
        {{/if}}
        {{if value.status==0}}
        <td>未锁定</td>
        {{/if}}
        {{if value.status==null}}
        <td></td>
        {{/if}}
        <td>{{role.modelName}}</td>
        <td><input value="删除" type="button"  onclick="return del('{{value.account}}','{{role.modelName}}')"></td>
        <td><input value="修改" type="button"  onclick="return update('{{value.account}}')"></td>
    </tr>
    {{/each}}
    {{/each}}
    {{/each}}
</script>

<script>
    $(function () {
        showPage({
            currentPage: 1,
            pageSize: 2,
            url: '/getAll',
            templateId: 'userListTemplate',
            contentId: 'tableBody',
            params: {
                id: 1
            }
        })
    })
    function del(obj,obj2) {
        //console.log(obj.parentElement.parentElement.children.item(0).innerHTML)
        if(confirm("确认删除？")){
            Ajax.post(
                "/deletescumuser",
                {account:obj,
                 modelName:obj2},
                function (result) {
                    show('user/scmUserList.html')
                    alert(result.msg)
                }
            )
        }else{
            return false;
        }

    }
    function update(obj) {
        Ajax.getHtml('user/userUpdate.html', function (html) {
            layer.open({
                type: 1,
                title: '修改用户',
                area: ['600px'],
                content: html,
                btn: ['确认', '取消'],
                yes: function () {
                    updateUser()
                },
                btn2: function () {
                    console.log('取消修改用户')
                }
            })
        })
        Ajax.post(
            "selectByAccount",
            {account:obj},
            function (result) {
                $("#accountname").val(result.data.account)
                $("#password").val(result.data.password)
                $("#Uname").val(result.data.name)
                if(result.data.status){
                    $('input[type=radio][value="1"]').attr("checked",true)
                }else{
                    $('input[type=radio][value="0"]').attr("checked",true)
                }
            }
        )
        Ajax.post(
            "selectModelName",
            {account:obj},
            function (result) {
                for(var i=0;i<result.data.length;i++){
                    if(result.data[i]=="admin"){
                        $('input[type=checkbox][value="admin"]').attr("checked",true)
                    }
                    if(result.data[i]=="purchase"){
                        $('input[type=checkbox][value="purchase"]').attr("checked",true)
                    }
                    if(result.data[i]=="stock"){
                        $('input[type=checkbox][value="stock"]').attr("checked",true)
                    }
                    if(result.data[i]=="sell"){
                        $('input[type=checkbox][value="sell"]').attr("checked",true)
                    }
                    if(result.data[i]=="finance"){
                        $('input[type=checkbox][value="finance"]').attr("checked",true)
                    }
                }

            }
        )
    }
</script>
